{extend name="/index/base" /}

{block name="content"}
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="__SELF__" data-auto="true" method="post">

            {foreach $nodes as $key=>$vo}
            <h2><input type="checkbox" name="nodes[]" value="{$vo.node}" {if in_array($vo.node, $is_chose)} checked="checked" {/if} />{$vo.title?$vo.title:$vo.node}</h2>
            <table>
                {foreach $vo['_sub_'] as $key1=>$vo1}
                <tr>
                    <td>&nbsp;&nbsp;&nbsp;<input type="checkbox" name="nodes[]" value="{$vo1.node}" {if in_array($vo1.node, $is_chose)} checked="checked" {/if} />{$vo1.title?$vo1.title:$vo1.node}</td>
                </tr>
                <tr>
                    <td>{foreach $vo1['_sub_'] as $key2=>$vo2}
                        <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="nodes[]" value="{$vo2.node}" {if in_array($vo2.node, $is_chose)} checked="checked" {/if} /> {$vo2.title?$vo2.title:$vo2.node} </span>
                        {/foreach}
                    </td>
                </tr>
                {/foreach}
            </table>
            {/foreach}

            <div class="layui-form-item text-center">
                {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
                <button class="layui-btn" type='submit'>保 存</button>
                <a  class="layui-btn layui-btn-danger" href="{:URL('admin/auth/index')}" >返 回</a>
            </div>
        </form>
    </div>
</div>

{/block}


{block name="script"}
<script>
    layui.use(['layer','table','form'],function () {
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$ //由于layer弹层依赖jQuery，所以可以直接得到
        //用户表格初始化
        var dataTable = table.render({
            elem: '#dataTable'
            ,height: 500
            ,url: "{:URL('admin/auth/getList')}" //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {checkbox: true,fixed: true}
                ,{field: 'id', title: 'ID', sort: true,width:80}
                ,{field: 'title', title: '角色名称'}
                ,{field: 'desc', title: '描述'}
                ,{field: 'status', title: '状态'}
                ,{fixed: 'right', width: 220, align:'center', toolbar: '#options'}
            ]]
        });

        //监听工具条
        table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'del'){
                layer.confirm('确认删除吗？', function(index){
                    layer.msg(data.id)
                    $.post("{{ route('admin.article.destroy') }}",{_method:'delete',ids:[data.id]},function (result) {
                        if (result.code==0){
                            obj.del(); //删除对应行（tr）的DOM结构
                        }
                        layer.close(index);
                        layer.msg(result.msg)
                    });
                });
            } else if(layEvent === 'edit'){
                layer.msg(data.id)
                //location.href = '/admin/article/'+data.id+'/edit';
            }
        });

        //搜索
        $('#submit').click(function () {
            var title = $(".title").val()
            var desc = $(".desc").val();

            var data = {'title':title,'desc':desc};

            $.ajax({
                type: 'POST',
                url: '{:url("admin/auth/store")}',
                data: data,
                success: function (ret) {
                    if (ret.code == 200) {
                        layer.msg(ret.msg, {icon: 6, time: 1000}, function () {
                            window.location.href='{:url("admin/auth/index")}';
                        });
                    }
                    return false;
                }
            });
        })


    })
</script>
{/block}
